package com.gitee.hioove.io;

import org.junit.jupiter.api.Test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Demo {
    public static void main(String[] args) {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        String s;
        try {
            while ((s = r.readLine()) != null) {
                long a = 0;
                char[] substring = s.substring(2).toCharArray();
                for (int i = 0; i < substring.length; i++) {
                    Character c = substring[i];
                    if (Character.isDigit(c)) {
                        a += Integer.parseInt(c.toString()) * Math.pow(16, i);
                    } else {
                        int b = (int) c - (int) ('a') + 10;
                        a += (int) (Integer.parseInt(c.toString()) * Math.pow(16, i));
                    }
                }
                System.out.println(a);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    @Test
    void test08() {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        String s;
        try {
            while ((s = r.readLine()) != null) {
                int a = 0;
                char[] substring = s.substring(2).toCharArray();
                for (int i = 0; i < substring.length; i++) {
                    Character c = substring[i];
                    if (Character.isDigit(c)) {
                        a += (int) (c * Math.pow(16, i));
                    } else {
                        int b = (int) c - (int) ('a') + 10;
                        a += (int) (c * Math.pow(16, i));
                    }
                }
                System.out.println(a);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
